/**
	Utility class to easily place objects onto the stage with respect for shift in stage width

	@author Matthew Richmond
	@version 2006-11-01

	@usage Activate with:
	<code>

	private var layoutCalc:LayoutCalculator;
	layoutCalc = new LayoutCalculator(950, 690);
	
	obj.attachMovie("miniLightsTL_id", "lightsTL_mc", d, {_x:layoutCalc.getL(), _y:layoutCalc.getT()} );
	obj.attachMovie("miniLightsTR_id", "lightsTR_mc", d, {_x:layoutCalc.getR(), _y:layoutCalc.getT()} );
	obj.attachMovie("miniLightsBR_id", "lightsBR_mc", d, {_x:layoutCalc.getR(), _y:layoutCalc.getB()} );
	obj.attachMovie("miniLightsBL_id", "lightsBL_mc", d, {_x:layoutCalc.getL(), _y:layoutCalc.getB()} );

	</code>

*/
class timber.ui.LayoutCalculator {

	private var initWidth:Number;
	private var initHeight:Number;
	private var currentWidth:Number;
	private var currentHeight:Number;
	private var deltaWidth:Number;
	private var deltaHeight:Number;
	
	private var minWidth:Number;
	private var minHeight:Number;

// ===========================================================
// - CONSTRUCTOR
// ===========================================================

	/**
	Constructor stores the initial physical width and height of the swf

	@param	w Number of pixels in actual physical width of swf (do not use Stage.width)
	@param	h Number of pixels in actual physical height of swf (do not use Stage.height)
	*/
	function LayoutCalculator (w:Number, h:Number) {
		//trace("LayoutCalculator");
		
		this.initWidth = w;
		this.initHeight = h;
	};

// ===========================================================
// - SET ACCESSORS
// ===========================================================

	function setMinWidth (val:Number){
		//trace("LayoutCalculator: setMinWidth");
	
		this.minWidth = val
	};

	function setMinHeight (val:Number){
		//trace("LayoutCalculator: setMinHeight");
	
		this.minHeight = val
	};

// ===========================================================
// - CALC ACCESSORS
// ===========================================================

	function getL ():Number{
		//trace("LayoutCalculator: getL");
		
		var c:Number;
		getCurrentWidth();
		c = 0 - (deltaWidth * .5);

		return c;
	};

	function getR ():Number{
		//trace("LayoutCalculator: getR");
		
		var c:Number;
		getCurrentWidth();
		c = initWidth + (deltaWidth * .5);

		return c;
	};
	
	function getT ():Number{
		//trace("LayoutCalculator: getT");
		
		var c:Number;
		getCurrentHeight();
		c = 0 - (deltaHeight * .5);

		return c;
	};
	
	function getB ():Number{
		//trace("LayoutCalculator: getB");
		
		var c:Number;
		getCurrentHeight();
		c = initHeight + (deltaHeight * .5);

		return c;
	};

// ===========================================================
// - UPDATE WIDTH AND HEIGHT
// ===========================================================

	function getCurrentWidth (){
		//trace("LayoutCalculator: getCurrentWidth");
		currentWidth = Stage.width;
		
		if (minWidth) {
			if (currentWidth < minWidth) currentWidth = minWidth;
		}
		
		deltaWidth = currentWidth - initWidth;
	};
	
	function getCurrentHeight (){
		//trace("LayoutCalculator: getCurrentHeight");
		currentHeight = Stage.height;
		
		if (minHeight) {
			if (currentHeight < minHeight) currentHeight = minHeight;
		}
		
		deltaHeight = currentHeight - initHeight;
	};
};